﻿<!-- 正文开始 -->
<div class="layui-form toolbar " lay-filter="org-charge-record-search-div">
    <div class="layui-form-item ">
        <div class="layui-inline " style="width: 120px;">
            <select id="sltKey">
                <option value="">-搜索条件-</option>
                <option value="user_id">ID</option>
                <option value="username">账号</option>
                <option value="nick_name">用户名</option>
                <option value="phone">手机号</option>
            </select>
        </div>
        <div class="layui-inline ">
            <input id="edtSearch" class="layui-input" type="text" placeholder="输入关键字"/>
        </div>
        <div class="layui-inline ">
            <button id="org-charge-record-search-btn" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
    </div>
</div>
<table class="layui-table layui-form" id="org-charge-record-table" lay-filter="org-charge-record-table"></table>
<div class="layui-table-tool" id="org-charge-record-toolbar">
    <div class="layui-table-tool-temp">
        <button id="org-charge-record-add-btn" lay-perm='sys_user_add'
                class="layui-btn layui-btn-primary layui-btn-sm icon-btn"><i
                class="layui-icon">&#xe654;</i>添加
        </button>
        <button id="org-meal-export-btn" class="layui-btn icon-btn layui-btn-primary layui-btn-sm"><i
                class="layui-icon">&#xe67d;</i>导出
        </button>
    </div>
</div>
<!-- 表格操作列 -->
<div type="text/html" style="display: none" id="org-charge-record-operate">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-perm='sys_user_see' lay-event="see">详情</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-perm='sys_user_edit' lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-perm='sys_user_edit' lay-event="charge">充值</a>
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-perm = 'sys_user_del' lay-event="del">删除</a>-->
</div>

<!-- 表格状态列 -->
<script type="text/html" id="org-charge-record-state">
    <div class="layui-form" lay-filter="org-charge-record-switch">
        <input type="checkbox" value="{{d.id}}" lay-filter="org-charge-record-state" lay-skin="switch" lay-text="正常|锁定"
               {{d.state==1?'checked':''}}/>
    </div>
</script>
<script>

    layui.use(['layer', 'form', 'table', 'util', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        form.render("select", "org-charge-record-search-div")
        admin.renderTable({
            id: "org-charge-record-table",
            search: "org-charge-record-search",
            url: "org/charge/list",
            toolbar: '#org-charge-record-toolbar',
            defaultToolbar: ['filter'],
            cols: [[
                // {type: 'checkbox'},
                {field: 'name', sort: true, width: "10%", title: '企业名称', fixed: 'left'},
                {field: 'mobile', sort: true, width: "10%", title: '管理员手机', fixed: 'left'},
                // {field: 'state', sort: true, title: '手机号'},
                {
                    field: "createTime", width: "10%",
                    sort: true, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '充值时间'
                },

                {field: 'state', width: "10%", sort: true, templet: '#org-charge-record-state', title: '状态'},
                {align: 'center', toolbar: '#org-charge-record-operate', width: "10%", title: '操作', fixed: "right"}
            ]],
            initSort: {field: "createTime", type: "desc"}
        })

        // 添加按钮点击事件
        $('#org-charge-record-add-btn').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(org-charge-record-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === "del") {
                del(obj.data.id);
            } else if (layEvent === "see") {
                showEditModel(data, "see");
            } else if (layEvent === "charge") {
                charge(data);
            }
        });

        // 修改user状态
        form.on('switch(org-charge-record-state)', function (obj) {
            admin.req("org/account/changeState", {
                id: obj.elem.value,
                state: obj.elem.checked ? 0 : 1
            }, function (data) {
                layer.msg("", {icon: 1});
            }, "post", false, function () {
                $(obj.elem).prop('checked', !obj.elem.checked);
                form.render('checkbox', "org-charge-record-switch");
            });
        });

        // 导出excel
        $('#btnExp').click(function () {
            var checkRows = table.checkStatus('userTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(ins1.config.id, checkRows.data, 'xls');
            }
        });


        function del(userId) {
            admin.delete("org/account/delete/" + userId, {}, function () {
                layer.msg("删除成功", {icon: 1});
                table.reload('org-charge-record-table')
            })
        }

        // 显示表单弹窗
        function showEditModel(data, see) {
            admin.putTempData('org-charge-record-form-obj', data);
            admin.putTempData('org-charge-record-formOk', false);
            admin.openForm({
                see: see,
                title: data ? '修改用户' : '添加用户',
                submitId: "org-charge-record-submit",
                path: 'org/account/accountForm.html',
                end: function () {
                    admin.getTempData('org-charge-record-formOk') && table.reload('org-charge-record-table');  // 成功刷新表格
                }
            });
        }

        // 显示充值表单弹窗
        function charge(data) {
            admin.putTempData('org-charge-record-form-obj', data);
            admin.putTempData('org-charge-record-formOk', false);
            admin.openForm({
                title: '企业账户充值',
                submitId: "org-charge-record-charge-submit",
                path: 'org/account/accountCharge.html',
                end: function () {
                    admin.getTempData('org-charge-record-formOk') && table.reload('org-charge-record-table');  // 成功刷新表格
                }
            });
        }
    });
</script>

</body>
</html>